date

tag=r

nn=0

#lfc-ls /grid/t2k.org/nd280/raw/ND280/ND280/00001000_00001999/
#lcg-lr lfn:/grid/t2k.org/nd280/production006/B/mcp/neut/2010-11-air/magnet/run4/anal/oa_nt_beam_90400040-0010_cltzobu2i6uk_anal_000_prod6amagnet201011airc-bsdv01_2.root

proddir=$(readlink -f $(pwd) | awk -F\/ '{$2=""; $3="";$4="";$5="";$6="";$7="";$8="";$9="";print}'| tr -s ' ' '/')
echo $proddir

for ii in $(cat rawlist)
do
#[luxi@pplxint9 6BmcpAirneut]$ grep TIMEDOUT seel.log  | sort -u
#[SE][StatusOfGetRequest][ETIMEDOUT] httpg://srm-t2k.gridpp.rl.ac.uk:8443/srm/managerv2: User timeout over
#    
    for griddir in $(echo  "srm://t2ksrm.nd280.org/nd280data" "srm://se03.esc.qmul.ac.uk/t2k.org/nd280") #"srm://srm-t2k.gridpp.rl.ac.uk/castor/ads.rl.ac.uk/prod/t2k.org/nd280"
    do
        
        fin="$griddir$proddir/$ii"

        fout=$tag\file$nn.root
        
        #echo $fin $fout
        
        ntry=0
        while [ ! -e $ii -a $ntry -le 10 ]
        do
            echo "downloading $fout $ii ntry $ntry"
            lcg-cp -v --vo t2k.org $fin $fout
            
            if [ -e $fout ]
            then
                ln -s $fout $ii
            fi
            
            ntry=$( expr $ntry + 1 )
        done
        
        
    done
    
    nn=$( expr $nn + 1 )
    
done

date



